/**
 * Class:	MainController
 * 
 * Variables:
 * 
 * 		accessibility type variableName;
 * 		(e.g. "private List<String> beneficiaries;")
 * 
 * Remarks:
 * 
 * 		Kindly list only only accessible variables:
 * 			> non-private variables ( public, protected,
 * 			  default )
 * 			> private variables with getters and/or
 * 			  setters 
 * 		
 * 		Variables are set to private and can be accessed
 * 		only through their getters and setters.
 * 		
 * 		In this controller, one can add, search, view,
 * 		update and delete Activities.
 * 
 * @author ( Sharmaine Lim )
 * @version ( 2013-02-28 // YYYY-MM-DD )
 */

package controllers;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Calendar;

import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

import managers.*;
import models.*;

import views.MainView;
import views.activity.AddActivityView;
import views.activity.SearchActivityView;
import views.activity.volunteer.StringListPanel;

public class MainController extends AbstractController {
	
	/* Instance Variables */
	private MainView mainView;
	
	/* Add Activity Variables */
	private ArrayList<Organization> addOrganizationList;
	private ArrayList<String> addBeneficiaryList;
	private ArrayList<String> addAdviserList;
	private ArrayList<Participant> addParticipantList;
	
	/* Search Activity Variables */
	private ArrayList<Object> dueSearchDetails;
	private ArrayList<Object> searchDetails;
	private ArrayList<VolunteerActivity> volunteerResults;
	private ArrayList<CurriculumActivity> curriculumResults;
	private VolunteerActivity chosenVolunteerActivity;
	private CurriculumActivity chosenCurriculumActivity; 
	
	
	
	/**
	 * Constructors
	 */
	
	public MainController( MainView mainView ) {
		super();
		this.mainView = mainView;
		setupMainController();
	}
	
	
	
	/**
	 * Add Volunteer Activity
	 *		- allows the user to add an activity
	 *		- initializes the Views, or portions
	 *		  of Views, for adding an activity
	 * 
	 * Parameter
	 *		- n/a
	 *	
	 * Returns
	 *		- n/a
	 */
	private void addVolunteerActivity() {
		String title = mainView.addActivityView.vPanel1.txtTitle.getText();
		String type = (String)mainView.addActivityView.vPanel1.cmbType.getSelectedItem();
		Date dateFiled = new Date( Integer.parseInt( (String)mainView.addActivityView.vPanel2.cmbYearFiled.getSelectedItem() ),
								   mainView.addActivityView.vPanel2.cmbMonthFiled.getSelectedIndex(),
								   mainView.addActivityView.vPanel2.cmbDayFiled.getSelectedIndex() );
		Date dateApproved = new Date( Integer.parseInt( (String)mainView.addActivityView.vPanel2.cmbYearApproved.getSelectedItem() ),
									  mainView.addActivityView.vPanel2.cmbMonthApproved.getSelectedIndex(),
									  mainView.addActivityView.vPanel2.cmbDayApproved.getSelectedIndex() );
		Date dateOfActivity = new Date( Integer.parseInt( (String)mainView.addActivityView.vPanel2.cmbYearOfActivity.getSelectedItem() ),
										mainView.addActivityView.vPanel2.cmbMonthOfActivity.getSelectedIndex(),
										mainView.addActivityView.vPanel2.cmbDayOfActivity.getSelectedIndex() );
		Date dateDue = new Date( Integer.parseInt( (String)mainView.addActivityView.vPanel2.cmbYearDue.getSelectedItem() ),
								 mainView.addActivityView.vPanel2.cmbMonthDue.getSelectedIndex(),
								 mainView.addActivityView.vPanel2.cmbDayDue.getSelectedIndex() );
		ArrayList<Organization> organizations = new ArrayList<Organization>();
		for ( int i : mainView.addActivityView.vPanel1.lstOrganizations.getSelectedIndices() ) {
			organizations.add( addOrganizationList.get( i ) );
		}
		ArrayList<String> beneficiaries = new ArrayList<String>();
		for ( Object beneficiary : mainView.addActivityView.vPanel3.lstModelCurrent.toArray() ) {
			beneficiaries.add( (String)beneficiary );
		}
		ArrayList<String> advisers = new ArrayList<String>();
		for ( Object adviser : mainView.addActivityView.vPanel4.lstModelCurrent.toArray() ) {
			advisers.add( (String)adviser );
		}
		ArrayList<Participant> participants = new ArrayList<Participant>();
		for ( Object participant : mainView.addActivityView.vPanel5.lstModelCurrent.toArray() ) {
			String name = "";
			String courseDegree = "";
			boolean getCourse = false;
			
			for ( char cParticipant : ( (String)participant ).toCharArray() ) {
				if ( cParticipant == '(' ) {
					getCourse = true;
				}
				
				else if ( getCourse ) {
					courseDegree = courseDegree.concat( "" + cParticipant );
				}
				else {
					name = name.concat( "" + cParticipant );
				}
			}
			
			courseDegree = courseDegree.substring( 0, courseDegree.length() - 1 );
			name = name.substring( 0, name.length() - 1 );
			
			participants.add( new Participant( name, courseDegree ) );
		}
		
		ArrayList<String> remarks = new ArrayList<String>();
		if ( !mainView.addActivityView.vPanel6.txaRemark.getText().equals( "" ) ) {
			remarks.add( mainView.addActivityView.vPanel6.txaRemark.getText() );
		}
		
		if ( new VolunteerActivityManager().insertActivity( new VolunteerActivity( title,
				type, beneficiaries, remarks, dateFiled, dateApproved, dateOfActivity, dateDue,
				organizations, advisers, participants, false, null, null, null ) ).equals( "Success" ) ) {
			
			if ( confirmationMessages.isOperationSuccess() ) {
				JOptionPane.showMessageDialog( mainView, "The activity has been saved into the database!",
											   "Success!", JOptionPane.PLAIN_MESSAGE);
			}
			mainView.displaySearchActivityView( new SearchActivityView() );
			setupSearchActivity();
		}
		else {
			JOptionPane.showMessageDialog( mainView, "The activity could not be saved into the database.",
										   "Error!", JOptionPane.ERROR_MESSAGE );
		}
		
		
	}
	
	
	
	/**
	 * View Volunteer Activity
	 *		- allows the user to view a specific
	 *		  volunteer activity
	 *		- initializes the Views, or portions
	 *		  of Views, for viewing an activity
	 * 
	 * Parameter
	 *		- n/a ( can be changed )
	 *	
	 * Returns
	 *		- n/a
	 */
	private void viewVolunteerActivity() {
		mainView.searchActivityView.openView();
		
		String strHTML = "<html><head><style type='text/css'>" +
						 "body {font-family: Arial; margin: 0px; padding: 0px;}" +
						 "</style></head><body>" +
						 "<p><span style='font-size: 2em; font-weight: bold;'>" +
						 chosenVolunteerActivity.getTitle() + "</span><br />" +
						 chosenVolunteerActivity.getType();
		
		if ( chosenVolunteerActivity.isCanceled() ) {
			strHTML = strHTML.concat( " (Canceled)" );
		}
		
		strHTML = strHTML.concat( "</p><br /><p><strong>Date Filed:</strong> " +
								  chosenVolunteerActivity.getDateFiled().toUserFriendlyString() + "<br />" +
								  "<strong>Date Approved:</strong> " +
								  chosenVolunteerActivity.getDateApproved().toUserFriendlyString() + "<br />" +
								  "<strong>Date of Activity:</strong> " +
								  chosenVolunteerActivity.getDateOfActivity().toUserFriendlyString() + "<br />" +
								  "<strong>Date Due:</strong> " +
								  chosenVolunteerActivity.getDateDue().toUserFriendlyString() + "</p>" +
								  "<br /><p><strong>Organization/s:</strong> " +
								  chosenVolunteerActivity.getOrganizations().size() + "<ul>" );
		
		for ( Organization organization : chosenVolunteerActivity.getOrganizations() ) {
			strHTML = strHTML.concat( "<li>" + organization.getName() + " (" + organization.getType() + ")</li><br />" );
		}
		
		strHTML = strHTML.concat( "</ul><p><strong>Beneficiary/ies:</strong> " +
								  chosenVolunteerActivity.getBeneficiaries().size() + "<ul>" );
		
		for ( String beneficiary : chosenVolunteerActivity.getBeneficiaries() ) {
			strHTML = strHTML.concat( "<li>" + beneficiary + "</li><br />" );
		}
		
		strHTML = strHTML.concat( "</ul><p><strong>Adviser/s:</strong> " +
								  chosenVolunteerActivity.getAdvisers().size() + "<ul>" );
		
		for ( String adviser : chosenVolunteerActivity.getAdvisers() ) {
			strHTML = strHTML.concat( "<li>" + adviser + "</li><br />" );
		}
		
		strHTML = strHTML.concat( "</ul><p><strong>Participant/s:</strong> " +
								  chosenVolunteerActivity.getParticipants().size() + "<ul>" );
		
		for ( Participant participant : chosenVolunteerActivity.getParticipants() ) {
			strHTML = strHTML.concat( "<li>" + participant.getName() + 
									  " (" + participant.getCourseDegree() + ")</li><br />" );
		}
		
		strHTML = strHTML.concat( "</ul><p><strong>Remark/s:</strong><ul>" );
		
		for ( String remark : chosenVolunteerActivity.getRemarks() ) {
			strHTML = strHTML.concat( "<li>" + remark + "<br /><br /></li>" );
		}
		
		strHTML = strHTML.concat( "</ul><p><strong>Evaluations:</strong><ul>" +
								  "<li><strong>Pink Form 1 (Organization):</strong><br />" );
		
		if ( chosenVolunteerActivity.getOrganizationEvaluation() == null ) {
			strHTML = strHTML.concat( "Not submitted" );
		}
		else {
			strHTML = strHTML.concat( "Submitted" );
		}
		
		strHTML = strHTML.concat( "</li><br /><li><strong>Pink Form 2 (Adviser):</strong><br />" );
		
		if ( chosenVolunteerActivity.getAdviserEvaluation() == null ) {
			strHTML = strHTML.concat( "Not submitted" );
		}
		else {
			strHTML = strHTML.concat( "Submitted" );
		}
		
		strHTML = strHTML.concat( "</li><br /><li><strong>Pink Form 3 (Beneficiary):</strong><br />" );
		
		if ( chosenVolunteerActivity.getBeneficiaryEvaluation() == null ) {
			strHTML = strHTML.concat( "Not submitted" );
		}
		else {
			strHTML = strHTML.concat( "Submitted" );
		}
		
		strHTML = strHTML.concat( "</li></ul></body></html>" );
		
		mainView.searchActivityView.edpView.setText( strHTML );
	}
	
	
	
	/**
	 * Search Volunteer Activity
	 *		- allows the user to search for a volunteer
	 *		  activity
	 *		- initializes the Views, or portions of
	 *		  Views, for searching for a volunteer
	 *		  activity
	 * 
	 * Searchables for Volunteer Activities
	 * 		- activity title
	 * 		- activity type
	 * 		- date filed
	 * 		- date approved
	 * 		- date of activity
	 * 		- canceled
	 * 		- remarks
	 * 		- organization name
	 * 		- organization type
	 * 		- beneficiary name
	 * 		- evaluation (not available yet)
	 * 
	 * Parameter
	 *		- n/a
	 *	
	 * Returns
	 *		- n/a
	 */
	private void searchVolunteerActivity() {
		String title = mainView.searchActivityView.searchVolunteerActivityView.txtTitle.getText();
		String type = mainView.searchActivityView.searchVolunteerActivityView.txtType.getText();
		Date dateFiled = null;
		Date dateApproved = null;
		Date dateOfActivity = null;
		Date dateDue = null;
		ArrayList<Organization> organization = new ArrayList<Organization>();
		ArrayList<String> beneficiary = null;
		ArrayList<String> remark = null;
		int canceled = mainView.searchActivityView.searchVolunteerActivityView.cmbCanceled.getSelectedIndex();
		int hasEvaluations = mainView.searchActivityView.searchVolunteerActivityView.cmbHasEvaluations.getSelectedIndex();
		
		if ( !( mainView.searchActivityView.searchVolunteerActivityView.cmbYearFiled.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthFiled.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayFiled.getSelectedItem().equals( "" ) ) ) {
			
			dateFiled = new Date( Integer.parseInt( (String)mainView.searchActivityView.searchVolunteerActivityView.cmbYearFiled.getSelectedItem() ),
								  mainView.searchActivityView.searchVolunteerActivityView.cmbMonthFiled.getSelectedIndex(),
								  mainView.searchActivityView.searchVolunteerActivityView.cmbDayFiled.getSelectedIndex() );
		}
		
		if ( !( mainView.searchActivityView.searchVolunteerActivityView.cmbYearApproved.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthApproved.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayApproved.getSelectedItem().equals( "" ) ) ) {
			
			dateApproved = new Date( Integer.parseInt( (String)mainView.searchActivityView.searchVolunteerActivityView.cmbYearApproved.getSelectedItem() ),
									 mainView.searchActivityView.searchVolunteerActivityView.cmbMonthApproved.getSelectedIndex(),
									 mainView.searchActivityView.searchVolunteerActivityView.cmbDayApproved.getSelectedIndex() );
		}
		
		if ( !( mainView.searchActivityView.searchVolunteerActivityView.cmbYearOfActivity.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthOfActivity.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayOfActivity.getSelectedItem().equals( "" ) ) ) {
			
			dateOfActivity = new Date( Integer.parseInt( (String)mainView.searchActivityView.searchVolunteerActivityView.cmbYearOfActivity.getSelectedItem() ),
									   mainView.searchActivityView.searchVolunteerActivityView.cmbMonthOfActivity.getSelectedIndex(),
									   mainView.searchActivityView.searchVolunteerActivityView.cmbDayOfActivity.getSelectedIndex() );
		}
		
		if ( !( mainView.searchActivityView.searchVolunteerActivityView.cmbYearDue.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthDue.getSelectedItem().equals( "" ) ||
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayDue.getSelectedItem().equals( "" ) ) ) {
			
			dateDue = new Date( Integer.parseInt( (String)mainView.searchActivityView.searchVolunteerActivityView.cmbYearDue.getSelectedItem() ),
								mainView.searchActivityView.searchVolunteerActivityView.cmbMonthDue.getSelectedIndex(),
								mainView.searchActivityView.searchVolunteerActivityView.cmbDayDue.getSelectedIndex() );
		}
		
		if ( !mainView.searchActivityView.searchVolunteerActivityView.txtOrgName.getText().equals( "" ) ||
			 !mainView.searchActivityView.searchVolunteerActivityView.txtOrgType.getText().equals( "" ) ) {
			
			organization.add( new Organization( mainView.searchActivityView.searchVolunteerActivityView.txtOrgName.getText(),
												mainView.searchActivityView.searchVolunteerActivityView.txtOrgType.getText(),
												true ) );
		}
		
		if ( !mainView.searchActivityView.searchVolunteerActivityView.txtBeneficiary.getText().equals( "" ) ) {
			beneficiary.add( mainView.searchActivityView.searchVolunteerActivityView.txtBeneficiary.getText() );
		}
		
		if ( !mainView.searchActivityView.searchVolunteerActivityView.txtBeneficiary.getText().equals( "" ) ) {
			remark.add( mainView.searchActivityView.searchVolunteerActivityView.txtBeneficiary.getText() );
		}
		
		searchDetails = new ArrayList<Object>();
		searchDetails.add( new VolunteerActivity( title, type, beneficiary, remark, dateFiled, dateApproved,
				dateOfActivity, dateDue, organization, null, null, false, null, null, null ) );
		searchDetails.add( canceled );
		searchDetails.add( hasEvaluations );
		
		refreshSearchVolunteerActivityTable( mainView.searchActivityView );
	}
	
	
	
	/**
	 * Search Curriculum Activity
	 *		- allows the user to search for a curriculum
	 *		  activity
	 *		- initializes the Views, or portions of
	 *		  Views, for searching for a curriculum
	 *		  activity
	 * 
	 * Searchables for Curriculum Activities
	 * 		- activity title
	 * 		- activity type
	 * 		- date start
	 * 		- date end
	 * 		- course code
	 * 		- remarks
	 * 		- participant section (course code is required for this)
	 * 
	 * Parameter
	 *		- n/a
	 *	
	 * Returns
	 *		- n/a
	 */
	private void searchCurriculumActivity() {
		
	}
	
	
	
	/**
	 * Action Assigner / Setup
	 */
	
	private void setupMainController() {
		/* Add action listeners to buttons */
		mainView.dueActivityView.btnAddActivity.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				setupAddActivity();
			}
		});
		
		mainView.dueActivityView.btnNewSearch.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				setupSearchActivity();
			}
		});
		
		/* Search Details */
		Calendar calendar = Calendar.getInstance();
		Date dateDue = new Date( calendar.get( Calendar.YEAR ), calendar.get( Calendar.MONTH ) + 1,
								 calendar.get( Calendar.DATE ) );
		
		dueSearchDetails = new ArrayList<Object>();
		dueSearchDetails.add( new VolunteerActivity( null, null, null, null, null, null, null,
				dateDue, null, null, null, false, null, null, null ) );
		dueSearchDetails.add( 0 );
		dueSearchDetails.add( 1 );
		
		/* Display result table */
		refreshSearchVolunteerActivityTable( mainView.dueActivityView );
	}
	
	private void setupAddActivity() {
		mainView.displayAddActivityView( new AddActivityView() );
		addOrganizationList = new OrganizationManager().viewOrganization();
		addBeneficiaryList = new BeneficiaryManager().viewBeneficiary();
		addAdviserList = new AdviserManager().viewAdviser();
		addParticipantList = new ParticipantManager().viewParticipant();
		
		/* Choose Volunteer or Curriculum Panel */
		mainView.addActivityView.panel0.rdbtnCurriculumbasedActivity.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.panel0.rdbtnCurriculumbasedActivity.setSelected(true);
				mainView.addActivityView.panel0.rdbtnVolunteerbasedActivity.setSelected(false);
			}
		});
		
		mainView.addActivityView.panel0.rdbtnVolunteerbasedActivity.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.panel0.rdbtnCurriculumbasedActivity.setSelected(false);
				mainView.addActivityView.panel0.rdbtnVolunteerbasedActivity.setSelected(true);
			}
		});
		
		mainView.addActivityView.panel0.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.panel0.btnNext.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				if ( mainView.addActivityView.panel0.rdbtnCurriculumbasedActivity.isSelected() ) {
					System.out.println("Eep, under construction!"); //TODO
				}
				else {
					mainView.addActivityView.displayVPanel1();
				}
			}
		});
		
		setupAddVolunteerActivity();
	}
	
	private void setupAddVolunteerActivity() {
		/* General Panel */
		mainView.addActivityView.vPanel1.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel0();
			}
		});
		
		mainView.addActivityView.vPanel1.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.vPanel1.btnNext.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				boolean error = false;
				mainView.addActivityView.vPanel1.txtTitle.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel1.lstOrganizations.setBackground( Color.WHITE );
				
				/* Check if all fields are done */
				if ( mainView.addActivityView.vPanel1.txtTitle.getText().equals( "" ) ) {
					mainView.addActivityView.vPanel1.txtTitle.setBackground( Color.PINK );
					
					JOptionPane.showMessageDialog( mainView, "Please enter the activity title.",
												   "Error!", JOptionPane.ERROR_MESSAGE);
					error = true;
				}
				
				if ( mainView.addActivityView.vPanel1.lstOrganizations.getSelectedIndex() < 0 ) {
					mainView.addActivityView.vPanel1.lstOrganizations.setBackground( Color.PINK );
					
					JOptionPane.showMessageDialog( mainView, "Please choose at least one organization.",
							   "Error!", JOptionPane.ERROR_MESSAGE);
					error = true;
				}
				
				if ( !error ) {
					mainView.addActivityView.displayVPanel2();
					refreshAddActivityTable();
				}
			}
		});
		
		setupActivityType( mainView.addActivityView.vPanel1.cmbType );
		for ( Organization organization : addOrganizationList ) {
			mainView.addActivityView.vPanel1.lstModelOrganizations.addElement( organization.getName() );
		}
		
		/* Dates Panel */
		mainView.addActivityView.vPanel2.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel1();
				refreshAddActivityTable();
			}
		});
		
		mainView.addActivityView.vPanel2.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.vPanel2.btnNext.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				boolean error = false;
				mainView.addActivityView.vPanel2.cmbMonthFiled.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbDayFiled.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbYearFiled.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbMonthApproved.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbDayApproved.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbYearApproved.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbMonthOfActivity.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbDayOfActivity.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbYearOfActivity.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbMonthDue.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbDayDue.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel2.cmbYearDue.setBackground( Color.WHITE );
				
				/* Check if all have dates and check date validity */
				if ( checkDayValidity( "Date Filed",
									   mainView.addActivityView.vPanel2.cmbMonthFiled,
									   mainView.addActivityView.vPanel2.cmbDayFiled,
									   mainView.addActivityView.vPanel2.cmbYearFiled ) ) {
					
					error = true;
				}
				if ( checkDayValidity( "Date Approved",
									   mainView.addActivityView.vPanel2.cmbMonthApproved,
									   mainView.addActivityView.vPanel2.cmbDayApproved,
									   mainView.addActivityView.vPanel2.cmbYearApproved ) ) {
					error = true;
				}
				if ( checkDayValidity( "Date of Activity",
									   mainView.addActivityView.vPanel2.cmbMonthOfActivity,
									   mainView.addActivityView.vPanel2.cmbDayOfActivity,
									   mainView.addActivityView.vPanel2.cmbYearOfActivity ) ) {
					error = true;
				}
				if ( checkDayValidity( "Date Due",
									   mainView.addActivityView.vPanel2.cmbMonthDue,
									   mainView.addActivityView.vPanel2.cmbDayDue,
									   mainView.addActivityView.vPanel2.cmbYearDue ) ) {
					error = true;
				}
				
				if ( !error ) {
					if ( compareDates( mainView.addActivityView.vPanel2.cmbMonthFiled,
									   mainView.addActivityView.vPanel2.cmbDayFiled,
									   mainView.addActivityView.vPanel2.cmbYearFiled,
									   mainView.addActivityView.vPanel2.cmbMonthApproved,
									   mainView.addActivityView.vPanel2.cmbDayApproved,
									   mainView.addActivityView.vPanel2.cmbYearApproved ) ) {
						
						error = true;
					}
					if ( compareDates( mainView.addActivityView.vPanel2.cmbMonthApproved,
									   mainView.addActivityView.vPanel2.cmbDayApproved,
									   mainView.addActivityView.vPanel2.cmbYearApproved,
									   mainView.addActivityView.vPanel2.cmbMonthOfActivity,
									   mainView.addActivityView.vPanel2.cmbDayOfActivity,
									   mainView.addActivityView.vPanel2.cmbYearOfActivity ) ) {
						
						error = true;
					}
					if ( compareDates( mainView.addActivityView.vPanel2.cmbMonthOfActivity,
									   mainView.addActivityView.vPanel2.cmbDayOfActivity,
									   mainView.addActivityView.vPanel2.cmbYearOfActivity,
									   mainView.addActivityView.vPanel2.cmbMonthDue,
									   mainView.addActivityView.vPanel2.cmbDayDue,
									   mainView.addActivityView.vPanel2.cmbYearDue ) ) {
						
						error = true;
					}
				}
				
				if ( !error ) {
					mainView.addActivityView.displayVPanel3();
					refreshAddActivityTable();
				}
			}
		});
		
		setupDates( mainView.addActivityView.vPanel2.cmbMonthFiled,
					mainView.addActivityView.vPanel2.cmbDayFiled,
					mainView.addActivityView.vPanel2.cmbYearFiled );
		setupDates( mainView.addActivityView.vPanel2.cmbMonthApproved,
					mainView.addActivityView.vPanel2.cmbDayApproved,
					mainView.addActivityView.vPanel2.cmbYearApproved );
		setupDates( mainView.addActivityView.vPanel2.cmbMonthOfActivity,
					mainView.addActivityView.vPanel2.cmbDayOfActivity,
					mainView.addActivityView.vPanel2.cmbYearOfActivity );
		setupDates( mainView.addActivityView.vPanel2.cmbMonthDue,
					mainView.addActivityView.vPanel2.cmbDayDue,
					mainView.addActivityView.vPanel2.cmbYearDue );
		
		/* Beneficiary Panel */
		mainView.addActivityView.vPanel3.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel2();
				refreshAddActivityTable();
			}
		});
		
		mainView.addActivityView.vPanel3.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.vPanel3.btnNext.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				boolean error = false;
				
				mainView.addActivityView.vPanel3.lstCurrent.setBackground( Color.WHITE );
				
				if ( mainView.addActivityView.vPanel3.lstModelCurrent.isEmpty() ) {
					mainView.addActivityView.vPanel3.lstCurrent.setBackground( Color.PINK );
					
					JOptionPane.showMessageDialog( mainView, "Please choose at least one beneficiary.",
												   "Error!", JOptionPane.ERROR_MESSAGE);
					
					error = true;
				}
				
				if ( !error ) {
					mainView.addActivityView.displayVPanel4();
					refreshAddActivityTable();
				}
			}
		});
		
		for ( String beneficiary : addBeneficiaryList ) {
			mainView.addActivityView.vPanel3.lstModelExisting.addElement( beneficiary );
		}
		mainView.addActivityView.vPanel3.lstModelExisting.addListDataListener( null );
		mainView.addActivityView.vPanel3.lstModelCurrent.addListDataListener( null );
		
		mainView.addActivityView.vPanel3.btnAdd.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				addToStringList( mainView.addActivityView.vPanel3 );
			}
		});
		
		mainView.addActivityView.vPanel3.btnListAdd.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				moveLists( mainView.addActivityView.vPanel3.lstExisting,
						   mainView.addActivityView.vPanel3.lstCurrent );
			}
		});
		
		mainView.addActivityView.vPanel3.btnListRemove.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				moveLists( mainView.addActivityView.vPanel3.lstCurrent,
						   mainView.addActivityView.vPanel3.lstExisting );
			}
		});
		
		
		mainView.addActivityView.vPanel4.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel3();
				refreshAddActivityTable();
			}
		});
		
		mainView.addActivityView.vPanel4.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.vPanel4.btnNext.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				boolean error = false;
				
				mainView.addActivityView.vPanel4.lstCurrent.setBackground( Color.WHITE );
				
				if ( mainView.addActivityView.vPanel4.lstModelCurrent.isEmpty() ) {
					mainView.addActivityView.vPanel4.lstCurrent.setBackground( Color.PINK );
					
					JOptionPane.showMessageDialog( mainView, "Please choose at least one adviser.",
												   "Error!", JOptionPane.ERROR_MESSAGE);
					
					error = true;
				}
				
				if ( !error ) {
					mainView.addActivityView.displayVPanel5();
					refreshAddActivityTable();
				}
			}
		});
		
		for ( String adviser : addAdviserList ) {
			mainView.addActivityView.vPanel4.lstModelExisting.addElement( adviser );
		}
		mainView.addActivityView.vPanel4.lstModelExisting.addListDataListener( null );
		mainView.addActivityView.vPanel4.lstModelCurrent.addListDataListener( null );
		
		mainView.addActivityView.vPanel4.btnAdd.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				addToStringList( mainView.addActivityView.vPanel4 );
			}
		});
		
		mainView.addActivityView.vPanel4.btnListAdd.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				moveLists( mainView.addActivityView.vPanel4.lstExisting,
						   mainView.addActivityView.vPanel4.lstCurrent );
			}
		});
		
		mainView.addActivityView.vPanel4.btnListRemove.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				moveLists( mainView.addActivityView.vPanel4.lstCurrent,
						   mainView.addActivityView.vPanel4.lstExisting );
			}
		});
		
		
		mainView.addActivityView.vPanel5.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel4();
				refreshAddActivityTable();
			}
		});
		
		mainView.addActivityView.vPanel5.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.vPanel5.btnNext.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				boolean error = false;
				
				mainView.addActivityView.vPanel5.lstCurrent.setBackground( Color.WHITE );
				
				if ( mainView.addActivityView.vPanel5.lstModelCurrent.isEmpty() ) {
					mainView.addActivityView.vPanel5.lstCurrent.setBackground( Color.PINK );
					
					JOptionPane.showMessageDialog( mainView, "Please choose at least one participant.",
												   "Error!", JOptionPane.ERROR_MESSAGE);
					
					error = true;
				}
				
				if ( !error ) {
					mainView.addActivityView.displayVPanel6();
					refreshAddActivityTable();
				}
			}
		});
		
		for ( Participant participant : addParticipantList ) {
			mainView.addActivityView.vPanel5.lstModelExisting.addElement( participant.getName() +
					" (" + participant.getCourseDegree() + ")" );
		}
		mainView.addActivityView.vPanel5.lstModelExisting.addListDataListener( null );
		mainView.addActivityView.vPanel5.lstModelCurrent.addListDataListener( null );
		
		mainView.addActivityView.vPanel5.btnAdd.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				boolean error = false;
				String strParticipant = mainView.addActivityView.vPanel5.txtNewParticipant.getText();
				String strCourseDegree = mainView.addActivityView.vPanel5.txtCourseDegree.getText();
				
				if ( strParticipant.equals( "" ) ) {
					mainView.addActivityView.vPanel5.txtNewParticipant.setBackground( Color.PINK );
					error = true;
				}
				
				if ( strCourseDegree.equals( "" ) ) {
					mainView.addActivityView.vPanel5.txtCourseDegree.setBackground( Color.PINK );
					error = true;
				}
				
				for ( Object currentParticipant : mainView.addActivityView.vPanel5.lstModelCurrent.toArray() ) {
					if ( ( strParticipant + " (" + strCourseDegree + ")" ).equals( (String)currentParticipant ) ) {
						mainView.addActivityView.vPanel5.txtNewParticipant.setBackground( Color.PINK );
						mainView.addActivityView.vPanel5.txtCourseDegree.setBackground( Color.PINK );
						JOptionPane.showMessageDialog( mainView, "Participant already exists.",
													   "Error!", JOptionPane.ERROR_MESSAGE);
						error = true;
					}
				}
				
				for ( Object currentParticipant : mainView.addActivityView.vPanel5.lstModelExisting.toArray() ) {
					if ( ( strParticipant + " (" + strCourseDegree + ")" ).equals( (String)currentParticipant ) ) {
						mainView.addActivityView.vPanel5.txtNewParticipant.setBackground( Color.PINK );
						mainView.addActivityView.vPanel5.txtCourseDegree.setBackground( Color.PINK );
						JOptionPane.showMessageDialog( mainView, "Participant already exists.",
													   "Error!", JOptionPane.ERROR_MESSAGE);
						error = true;
					}
				}
				
				if ( error ) {
					return;
				}
				
				mainView.addActivityView.vPanel5.lstCurrent.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel5.txtNewParticipant.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel5.txtCourseDegree.setBackground( Color.WHITE );
				mainView.addActivityView.vPanel5.lstModelCurrent
						.addElement( strParticipant + " (" + strCourseDegree + ")" );
				mainView.addActivityView.vPanel5.txtNewParticipant.setText( "" );
				mainView.addActivityView.vPanel5.txtCourseDegree.setText( "" );
			}
		});
		
		mainView.addActivityView.vPanel5.btnListAdd.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				moveLists( mainView.addActivityView.vPanel5.lstExisting,
						   mainView.addActivityView.vPanel5.lstCurrent );
			}
		});
		
		mainView.addActivityView.vPanel5.btnListRemove.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				moveLists( mainView.addActivityView.vPanel5.lstCurrent,
						   mainView.addActivityView.vPanel5.lstExisting );
			}
		});
		
		
		mainView.addActivityView.vPanel6.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel5();
				refreshAddActivityTable();
			}
		});
		
		mainView.addActivityView.vPanel6.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.vPanel6.btnSave.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayConfirm();
				
				String strHTML = "<html><head><style type='text/css'>" +
						"body {font-family: Arial; margin: 0px; padding: 0px;}" +
						"</style></head><body>" +
						"<p><span style='font-size: 2em; font-weight: bold;'>" +
						mainView.addActivityView.vPanel1.txtTitle.getText() + "</span><br />" +
						mainView.addActivityView.vPanel1.cmbType.getSelectedItem() + "</p>" +
						"<p><strong>Date Filed:</strong> " +
						mainView.addActivityView.vPanel2.cmbMonthFiled.getSelectedItem() + " " +
						mainView.addActivityView.vPanel2.cmbDayFiled.getSelectedItem() + ", " +
						mainView.addActivityView.vPanel2.cmbYearFiled.getSelectedItem() + "<br />" +
						"<strong>Date Approved:</strong> " +
						mainView.addActivityView.vPanel2.cmbMonthApproved.getSelectedItem() + " " +
						mainView.addActivityView.vPanel2.cmbDayApproved.getSelectedItem() + ", " +
						mainView.addActivityView.vPanel2.cmbYearApproved.getSelectedItem() + "<br />" +
						"<strong>Date of Activity:</strong> " +
						mainView.addActivityView.vPanel2.cmbMonthOfActivity.getSelectedItem() + " " +
						mainView.addActivityView.vPanel2.cmbDayOfActivity.getSelectedItem() + ", " +
						mainView.addActivityView.vPanel2.cmbYearOfActivity.getSelectedItem() + "<br />" +
						"<strong>Date Due:</strong> " +
						mainView.addActivityView.vPanel2.cmbMonthDue.getSelectedItem() + " " +
						mainView.addActivityView.vPanel2.cmbDayDue.getSelectedItem() + ", " +
						mainView.addActivityView.vPanel2.cmbYearDue.getSelectedItem() + "</p>" +
						"<p><strong>Organization/s:</strong><ul>";
				
				for ( int i : mainView.addActivityView.vPanel1.lstOrganizations.getSelectedIndices() ) {
					strHTML = strHTML.concat( "<li>" + addOrganizationList.get( i ).getName() + "</li>" );
				}
				
				strHTML = strHTML.concat( "</ul><p><strong>Beneficiary/ies:</strong><ul>" );
				
				for ( Object beneficiary : mainView.addActivityView.vPanel3.lstModelCurrent.toArray() ) {
					strHTML = strHTML.concat( "<li>" + beneficiary + "</li>" );
				}
				
				strHTML = strHTML.concat( "</ul><p><strong>Adviser/s:</strong><ul>" );
				
				for ( Object adviser : mainView.addActivityView.vPanel4.lstModelCurrent.toArray() ) {
					strHTML = strHTML.concat( "<li>" + adviser + "</li>" );
				}
				
				strHTML = strHTML.concat( "</ul><p><strong>Participant/s:</strong><ul>" );
				
				for ( Object participant : mainView.addActivityView.vPanel5.lstModelCurrent.toArray() ) {
					strHTML = strHTML.concat( "<li>" + participant + "</li>" );
				}
				
				if ( !mainView.addActivityView.vPanel6.txaRemark.getText().equals( "" ) ) {
					strHTML = strHTML.concat( "</ul><p><strong>Remark:</strong><ul><li>" +
											  mainView.addActivityView.vPanel6.txaRemark.getText() + "</li>" );
				}
				
				strHTML = strHTML.concat( "</ul></body></html>" );
				
				mainView.addActivityView.confirmPanel.edpData.setText( strHTML );
				
				refreshAddActivityTable();
			}
		});
		
		
		mainView.addActivityView.confirmPanel.btnBack.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.addActivityView.displayVPanel6();
			}
		});
		
		mainView.addActivityView.confirmPanel.btnCancel.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displaySearchActivityView( new SearchActivityView() );
				setupSearchActivity();
			}
		});
		
		mainView.addActivityView.confirmPanel.btnSave.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				addVolunteerActivity();
			}
		});
	}
	
	private void setupSearchActivity(){
		mainView.displaySearchActivityView( new SearchActivityView() );
		mainView.searchActivityView.displayVolunteerActivitySearch();
		setupSearchVolunteerActivity();
		
		setupDates( mainView.searchActivityView.searchVolunteerActivityView.cmbMonthFiled,
					mainView.searchActivityView.searchVolunteerActivityView.cmbDayFiled,
					mainView.searchActivityView.searchVolunteerActivityView.cmbYearFiled );
		setupDates( mainView.searchActivityView.searchVolunteerActivityView.cmbMonthApproved,
					mainView.searchActivityView.searchVolunteerActivityView.cmbDayApproved,
					mainView.searchActivityView.searchVolunteerActivityView.cmbYearApproved );
		setupDates( mainView.searchActivityView.searchVolunteerActivityView.cmbMonthOfActivity,
					mainView.searchActivityView.searchVolunteerActivityView.cmbDayOfActivity,
					mainView.searchActivityView.searchVolunteerActivityView.cmbYearOfActivity );
		setupDates( mainView.searchActivityView.searchVolunteerActivityView.cmbMonthDue,
					mainView.searchActivityView.searchVolunteerActivityView.cmbDayDue,
					mainView.searchActivityView.searchVolunteerActivityView.cmbYearDue );
		
		mainView.searchActivityView.btnNewSearch.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				setupSearchActivity();
			}
		});
		
		mainView.searchActivityView.btnAddActivity.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				setupAddActivity();
			}
		});
		
		mainView.searchActivityView.rdbtnVolunteerbasedActivity.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.searchActivityView.rdbtnVolunteerbasedActivity.setSelected(true);
				mainView.searchActivityView.rdbtnCurriculumbasedActivity.setSelected(false);
				mainView.searchActivityView.displayVolunteerActivitySearch();
				setupSearchVolunteerActivity();
			}
		});
		
		mainView.searchActivityView.rdbtnCurriculumbasedActivity.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.searchActivityView.rdbtnVolunteerbasedActivity.setSelected(false);
				mainView.searchActivityView.rdbtnCurriculumbasedActivity.setSelected(true);
				mainView.searchActivityView.displayCurriculumActivitySearch();
				//setupSearchCurriculumActivity();
			}
		});
		
		mainView.searchActivityView.btnReturnToMain.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.displayDueActivityView();
			}
		});
		
		mainView.searchActivityView.tblResults.addMouseListener( new MouseListener() {
			public void mouseClicked( MouseEvent event ) {
				if ( mainView.searchActivityView.tblResults.getSelectedRow() > -1 &&
					 mainView.searchActivityView.tblResults.getSelectedRow() < volunteerResults.size() ) {
					
					chosenVolunteerActivity = volunteerResults.get( mainView.searchActivityView
																	.tblResults.getSelectedRow() );
					viewVolunteerActivity();
				}
			}
			
			public void mouseEntered( MouseEvent event ) {}
			
			public void mouseExited( MouseEvent event ) {}
			
			public void mousePressed( MouseEvent event ) {}
			
			public void mouseReleased( MouseEvent event ) {}
		});
		
		mainView.searchActivityView.btnClose.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.searchActivityView.closeView();
				chosenVolunteerActivity = null;
			}
		});
	}
	
	private void setupSearchVolunteerActivity() {
		mainView.searchActivityView.searchVolunteerActivityView.btnClear.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				mainView.searchActivityView.searchVolunteerActivityView.txtTitle.setText( "" );
				mainView.searchActivityView.searchVolunteerActivityView.txtType.setText( "" );
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthFiled.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayFiled.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbYearFiled.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthApproved.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayApproved.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbYearApproved.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthOfActivity.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayOfActivity.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbYearOfActivity.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbMonthDue.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbDayDue.setSelectedIndex( 0 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbYearDue.setSelectedIndex( 0 );
				
				mainView.searchActivityView.searchVolunteerActivityView.txtOrgName.setText( "" );
				mainView.searchActivityView.searchVolunteerActivityView.txtOrgType.setText( "" );
				mainView.searchActivityView.searchVolunteerActivityView.txtBeneficiary.setText( "" );
				mainView.searchActivityView.searchVolunteerActivityView.txaRemark.setText( "" );
				mainView.searchActivityView.searchVolunteerActivityView.cmbCanceled.setSelectedIndex( 2 );
				mainView.searchActivityView.searchVolunteerActivityView.cmbHasEvaluations.setSelectedIndex( 2 );
			}
		});
		
		mainView.searchActivityView.searchVolunteerActivityView.btnSearch.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				searchVolunteerActivity();
			}
		});
		
		mainView.searchActivityView.btnUpdate.addActionListener( new ActionListener() {
			public void actionPerformed( ActionEvent event ) {
				new UpdateActivityController( chosenVolunteerActivity );
			}
		});
	}
	
	private void setupActivityType( JComboBox<String> cmbType ) {
		cmbType.addItem( "Resource Mobilization" );
		cmbType.addItem( "Education for Youth" );
		cmbType.addItem( "Education for Adults" );
		cmbType.addItem( "Advocacy work" );
		cmbType.addItem( "Immersion/interaction with institutions" );
		cmbType.addItem( "Immersion/interaction with communities" );
		cmbType.addItem( "Environmental related" );
		cmbType.addItem( "Health related" );
		cmbType.addItem( "Disaster response related" );
		cmbType.addItem( "Others" );
	}
	
	private void setupDates( JComboBox<String> cmbMonth, JComboBox<String> cmbDay, JComboBox<String> cmbYear ) {
		cmbMonth.addItem( "" );
		cmbMonth.addItem( "January" );
		cmbMonth.addItem( "February" );
		cmbMonth.addItem( "March" );
		cmbMonth.addItem( "April" );
		cmbMonth.addItem( "May" );
		cmbMonth.addItem( "June" );
		cmbMonth.addItem( "July" );
		cmbMonth.addItem( "August" );
		cmbMonth.addItem( "September" );
		cmbMonth.addItem( "October" );
		cmbMonth.addItem( "November" );
		cmbMonth.addItem( "December" );
		
		cmbDay.addItem( "" );
		for ( int day = 1; day < 32; day++ ) {
			cmbDay.addItem( "" + day );
		}
		
		cmbYear.addItem( "" );
		for ( int year = 1911; year < Calendar.getInstance().get( Calendar.YEAR ) + 2; year++ ) {
			cmbYear.addItem( "" + year );
		}
	}
	
	private boolean compareDates( JComboBox<String> cmbMonth1, JComboBox<String> cmbDay1, JComboBox<String> cmbYear1,
								  JComboBox<String> cmbMonth2, JComboBox<String> cmbDay2, JComboBox<String> cmbYear2 ) {
		boolean error = false;
		
		if ( cmbYear2.getSelectedIndex() < cmbYear1.getSelectedIndex() ) {
			error = true;
		}
		else if ( cmbYear2.getSelectedIndex() == cmbYear1.getSelectedIndex() ) {
			
			if ( cmbMonth2.getSelectedIndex() < cmbMonth1.getSelectedIndex() ) {
				error = true;
			}
			
			else if ( cmbMonth2.getSelectedIndex() == cmbMonth1.getSelectedIndex() &&
					  cmbDay2.getSelectedIndex() < cmbDay1.getSelectedIndex() ) {
				error = true;
			}
		}
		
		if ( error ) {
			cmbMonth1.setBackground( Color.PINK );
			cmbDay1.setBackground( Color.PINK );
			cmbYear1.setBackground( Color.PINK );
			cmbMonth2.setBackground( Color.PINK );
			cmbDay2.setBackground( Color.PINK );
			cmbYear2.setBackground( Color.PINK );
			
			JOptionPane.showMessageDialog( mainView, "Error in the sequence of dates.",
										   "Error!", JOptionPane.ERROR_MESSAGE);
		}
		
		return error;
	}
	
	private boolean checkDayValidity( String name, JComboBox<String> cmbMonth, JComboBox<String> cmbDay, JComboBox<String> cmbYear ) {
		boolean error = false;
		int month = cmbMonth.getSelectedIndex();
		int year;
		int day;
		
		try {
			day = Integer.parseInt( (String)cmbDay.getSelectedItem() );
			year = Integer.parseInt( (String)cmbYear.getSelectedItem() );
			
			if ( month < 1 ) {
				error = true;
			}
			else if ( month == 2 ) {
				if ( year % 4 == 0 && day > 29 ) {
					error = true;
				}
				else if ( year % 4 != 0 && day > 28 ) {
					error = true;
				}
			}
			else if ( ( month == 4 || month == 6 || month == 9 || month == 11 ) && day > 30 ) {
				error = true;
			}
		} catch ( Exception e ) {
			error = true;
		}
		
		if ( error ) {
			cmbMonth.setBackground( Color.PINK );
			cmbDay.setBackground( Color.PINK );
			cmbYear.setBackground( Color.PINK );
			
			JOptionPane.showMessageDialog( mainView, "Invalid date for " + name + ".",
										   "Error!", JOptionPane.ERROR_MESSAGE);
		}
		
		return error;
	}
	
	private void moveLists( JList<String> lstFrom, JList<String> lstTo ) {
		if ( lstFrom.getSelectedValue() != null ) {
			
			DefaultListModel<String> lstModelFrom = (DefaultListModel<String>)lstFrom.getModel();
			DefaultListModel<String> lstModelTo = (DefaultListModel<String>)lstTo.getModel();
			
			for ( Object value : lstFrom.getSelectedValuesList() ) {
				lstModelTo.addElement( (String)value );
				lstModelFrom.removeElement( value );
			}
			
			mainView.addActivityView.vPanel3.lstCurrent.setBackground( Color.WHITE );
		}
	}
	
	private void addToStringList( StringListPanel panel ) {
		boolean error = false;
		
		if ( panel.txtNewString.getText().equals( "" ) ) {
			panel.txtNewString.setBackground( Color.PINK );
			error = true;
		}
		
		for ( Object currentString : panel.lstModelCurrent.toArray() ) {
			if ( panel.txtNewString.getText().equals( currentString ) ) {
				panel.txtNewString.setBackground( Color.PINK );
				JOptionPane.showMessageDialog( mainView, panel.type + " already exists.",
											   "Error!", JOptionPane.ERROR_MESSAGE);
				error = true;
			}
		}
		
		for ( Object currentString : panel.lstModelExisting.toArray() ) {
			if ( panel.txtNewString.getText().equals( currentString ) ) {
				panel.txtNewString.setBackground( Color.PINK );
				JOptionPane.showMessageDialog( mainView, panel.type + " already exists.",
											   "Error!", JOptionPane.ERROR_MESSAGE);
				error = true;
			}
		}
		
		if ( !error ) {
			panel.lstCurrent.setBackground( Color.WHITE );
			panel.txtNewString.setBackground( Color.WHITE );
			panel.lstModelCurrent.addElement( panel.txtNewString.getText() );
			panel.txtNewString.setText( "" );
		}
	}
	
	private void refreshAddActivityTable() {
		boolean writeField;
		
		/* Clear Table */
		while ( mainView.addActivityView.tblModelDetails.getRowCount() > 0 ) {
			mainView.addActivityView.tblModelDetails.removeRow( 0 );
		}
		
		/* Add Title */
		mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Activity Title",
				mainView.addActivityView.vPanel1.txtTitle.getText() } );
		
		/* Add Type */
		mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Activity Type",
				mainView.addActivityView.vPanel1.cmbType.getSelectedItem() } );
		
		writeField = true;
		
		/* Add Organizations */
		for ( int i : mainView.addActivityView.vPanel1.lstOrganizations.getSelectedIndices() ) {
			if ( writeField ) {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Organization/s",
					addOrganizationList.get( i ).getName() } );
				writeField = false;
			}
			else {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "",
					addOrganizationList.get( i ).getName() } );
			}
		}
		
		/* Add Dates */
		if ( !( mainView.addActivityView.vPanel2.cmbYearFiled.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbMonthFiled.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbDayFiled.getSelectedItem().equals( "" ) ) ) {
			
			mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Date Filed",
					mainView.addActivityView.vPanel2.cmbMonthFiled.getSelectedItem() + " " +
					mainView.addActivityView.vPanel2.cmbDayFiled.getSelectedItem() + ", " +
					mainView.addActivityView.vPanel2.cmbYearFiled.getSelectedItem() } );
		}
		
		if ( !( mainView.addActivityView.vPanel2.cmbYearApproved.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbMonthApproved.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbDayApproved.getSelectedItem().equals( "" ) ) ) {
			
			mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Date Approved",
					mainView.addActivityView.vPanel2.cmbMonthApproved.getSelectedItem() + " " +
					mainView.addActivityView.vPanel2.cmbDayApproved.getSelectedItem() + ", " +
					mainView.addActivityView.vPanel2.cmbYearApproved.getSelectedItem() } );
			
		}
		
		if ( !( mainView.addActivityView.vPanel2.cmbYearOfActivity.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbMonthOfActivity.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbDayOfActivity.getSelectedItem().equals( "" ) ) ) {
			
			mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Date of Activity",
					mainView.addActivityView.vPanel2.cmbMonthOfActivity.getSelectedItem() + " " +
					mainView.addActivityView.vPanel2.cmbDayOfActivity.getSelectedItem() + ", " +
					mainView.addActivityView.vPanel2.cmbYearOfActivity.getSelectedItem() } );
			
		}
		
		if ( !( mainView.addActivityView.vPanel2.cmbYearDue.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbMonthDue.getSelectedItem().equals( "" ) ||
				mainView.addActivityView.vPanel2.cmbDayDue.getSelectedItem().equals( "" ) ) ) {
		
			mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Date Due",
					mainView.addActivityView.vPanel2.cmbMonthDue.getSelectedItem() + " " +
					mainView.addActivityView.vPanel2.cmbDayDue.getSelectedItem() + ", " +
					mainView.addActivityView.vPanel2.cmbYearDue.getSelectedItem() } );
		}
		
		writeField = true;
		
		/* Add Beneficiaries */
		for ( Object beneficiary : mainView.addActivityView.vPanel3.lstModelCurrent.toArray() ) {
			if ( writeField ) {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Beneficiary/ies",
					beneficiary } );
				writeField = false;
			}
			else {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "",
					beneficiary } );
			}
		}
		
		writeField = true;
		
		/* Add Advisers */
		for ( Object adviser : mainView.addActivityView.vPanel4.lstModelCurrent.toArray() ) {
			if ( writeField ) {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Adviser/s",
					adviser } );
				writeField = false;
			}
			else {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "",
					adviser } );
			}
		}
		
		writeField = true;
		
		/* Add Advisers */
		for ( Object participant : mainView.addActivityView.vPanel5.lstModelCurrent.toArray() ) {
			if ( writeField ) {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Participant/s",
					participant } );
				writeField = false;
			}
			else {
				mainView.addActivityView.tblModelDetails.addRow( new Object[] { "",
					participant } );
			}
		}
		
		/* Add Remark */
		if ( !mainView.addActivityView.vPanel6.txaRemark.getText().equals( "" ) ) {
			mainView.addActivityView.tblModelDetails.addRow( new Object[] { "Remark",
					mainView.addActivityView.vPanel6.txaRemark.getText() } );
		}
	}
	
	private void refreshSearchVolunteerActivityTable( SearchActivityView view ) {
		view.displayResults();
		
		if ( view == mainView.searchActivityView ) {
			volunteerResults = new VolunteerActivityManager().searchActivity( (VolunteerActivity)searchDetails.get( 0 ),
																			  (int)searchDetails.get( 1 ),
																			  (int)searchDetails.get( 2 ) );
		}
		else {
			volunteerResults = new VolunteerActivityManager().searchActivity( (VolunteerActivity)dueSearchDetails.get( 0 ),
																			  (int)dueSearchDetails.get( 1 ),
																			  (int)dueSearchDetails.get( 2 ) );
		}
		view.tblModelResults = new DefaultTableModel( new Object[][] {},
																   new String[] { "Activity Title",
																				  "Activity Type",
																				  "Sponsoring Organization/s",
																				  "Beneficiary/ies",
																				  "Requirements Due Date" } );
		
		view.tblResults.setModel( view.tblModelResults );
		
		for ( VolunteerActivity activity : volunteerResults ) {
			String organizations = "";
			String beneficiaries = "";
			String requirementsDue = null;
			
			for ( int i = 0; i < activity.getOrganizations().size(); i++ ) {
				if ( i == activity.getOrganizations().size() - 1 ) {
					organizations = organizations.concat( activity.getOrganizations().get( i ).getName() );
				}
				else {
					organizations = organizations.concat( activity.getOrganizations().get( i ).getName() + ", " );
				}
			}
			for ( int i = 0; i < activity.getBeneficiaries().size(); i++ ) {
				if ( i == activity.getBeneficiaries().size() - 1 ) {
					beneficiaries = beneficiaries.concat( activity.getBeneficiaries().get( i ) );
				}
				else {
					beneficiaries = beneficiaries.concat( activity.getBeneficiaries().get( i ) + ", " );
				}
			}
			
			if ( activity.getOrganizationEvaluation() != null && activity.getAdviserEvaluation() != null &&
				 activity.getBeneficiaryEvaluation() != null ) {
				
				requirementsDue = "Evaluations submitted";
			}
			else {
				requirementsDue = activity.getDateDue().toUserFriendlyString();
			}
			
			view.tblModelResults.addRow( new String[] { activity.getTitle(),
					activity.getType(), organizations, beneficiaries, requirementsDue } );
		}

		view.tblResults.setPreferredSize( new Dimension(730, 16 * (volunteerResults.size() + 1) ) );
		
		view.tblModelResults.addRow( new String[] { "", "", "Found " + volunteerResults.size() + " results!" } );
	}
}
